package com.shujunjun.project.springes.controller;

import com.shujunjun.project.springes.entity.TaskExecute;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.query.BaseQuery;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.web.bind.annotation.*;

/**
 * @author wsh
 * @since 2024/8/29 21:06
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class TaskController {

    final ElasticsearchOperations elasticsearchOperations;

    @PostMapping(value = "task")
    public String save(@RequestBody TaskExecute taskExecute) {
        TaskExecute task = elasticsearchOperations.save(taskExecute);
        return task.getContainerNo();
    }

    @GetMapping(value = "task/{id}")
    public TaskExecute get(@PathVariable("id") String id) {
        TaskExecute taskExecute = elasticsearchOperations.get(id, TaskExecute.class);
        log.info("task:{}", taskExecute);
        return taskExecute;
    }

    @GetMapping(value = "{id}")
    public TaskExecute get(@PathVariable("id") Integer id) {
        return null;
    }
}
